package com.zdb.controller;

import com.zdb.common.Result;
import com.zdb.pojo.dto.LoginDto;
import com.zdb.service.AuthenticationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/authentic")
public class AuthController {
    private static final Logger log = LoggerFactory.getLogger(AuthController.class);
    @Autowired
    private AuthenticationService authenticationService;
    @PostMapping("/login")
    public Result login(@RequestBody LoginDto loginDto)  {
        log.info("login username:{},password:{}",loginDto.getUsername(),loginDto.getPassword());
        String token = authenticationService.login(loginDto.getUsername(), loginDto.getPassword());
        log.info("token:{}",token);
        return Result.sucess("登录成功",token);
    }

    @GetMapping("/info")
    public Result info(){
        return Result.sucess(null,authenticationService.getUserInfo());
    }

}
